package nc.pubimpl.mmpac.sumpickm.ic;

import nc.bs.mmpac.sumpickm.bp.query.SumPickmQueryBP;
import nc.bs.mmpac.sumpickm.bp.rewrite.SumPickmRewriteBodyFor4DBP;
import nc.bs.mmpac.sumpickm.bp.rewrite.SumPickmRewriteSumFor4DBP;
import nc.pubitf.mmpac.sumpickm.ic.IPublicSumPickmServiceFor4D;
import nc.util.mmf.framework.base.MMValueCheck;
import nc.vo.mmpac.sumpickm.entity.AggSumPickmVO;
import nc.vo.mmpac.sumpickm.param.SumPickmTransParamFor4D;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.pub.MapList;

public class PublicSumPickmServiceFor4DImpl implements IPublicSumPickmServiceFor4D {

    @Override
    public void rewriteFor4D(SumPickmTransParamFor4D[] params) throws BusinessException {
        if (MMValueCheck.isEmpty(params)) {
            return;
        }
        MapList<String, SumPickmTransParamFor4D> sparamMap = new MapList<String, SumPickmTransParamFor4D>();
        MapList<String, SumPickmTransParamFor4D> bparamMap = new MapList<String, SumPickmTransParamFor4D>();
        for (SumPickmTransParamFor4D param : params) {
            if (MMValueCheck.isTrue(param.getIsSum())) {
                sparamMap.put(param.getBid(), param);
            }
            else {
                bparamMap.put(param.getBid(), param);
            }
        }
        SumPickmQueryBP queryBP = new SumPickmQueryBP();
        if (MMValueCheck.isNotEmpty(sparamMap)) {
            AggSumPickmVO[] aggSumPickmVOs = queryBP.queryAggVObySids(sparamMap.keySet().toArray(new String[0]));
            if (MMValueCheck.isNotEmpty(aggSumPickmVOs)) {
                SumPickmRewriteSumFor4DBP reWriteSumBP = new SumPickmRewriteSumFor4DBP();
                reWriteSumBP.rewriteSumFor4D(sparamMap, aggSumPickmVOs);
            }
        }
        if (MMValueCheck.isNotEmpty(bparamMap)) {
            AggSumPickmVO[] aggSumPickmVOs = queryBP.queryAggVObyBids(bparamMap.keySet().toArray(new String[0]));
            if (MMValueCheck.isNotEmpty(aggSumPickmVOs)) {
                SumPickmRewriteBodyFor4DBP reWriteBodyBP = new SumPickmRewriteBodyFor4DBP();
                reWriteBodyBP.rewriteBodyFor4D(bparamMap, aggSumPickmVOs);
            }
        }
    }

}
